package com.annhoa.domain.repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.annhoa.domain.entity.SysUser;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

/**
 * 
 * @author admin
 *
 */
public interface SysUserRepository extends Repository<SysUser, Long> {
	
	
	static final Map<String, SysUser> userMap = new HashMap<>();

	@Query(value = "from SysUser where username=:username")
	SysUser findByUsername(@Param("username")String username);

	@Query(value = "from SysUser where name=:name")
	List<SysUser> findByName1(@Param("name") String name);

	@Query(value = "select * from #{#entityName} u where u.name=?1", nativeQuery = true)
	List<SysUser> findByName2(String name);

	List<SysUser> findByName(String name);
	
	List<SysUser> findByName(String name, Sort sort);
	
	//两表联合查询
	//@Query(value="select new com.annhoa.domian.UserAndAddr(u,a) from User u,Address a where u.addressId = a.addressId")
	//List<UserAndAddr> findUserAndAddr();
 	public default SysUser insert(SysUser sysUser){
        userMap.put(sysUser.getUsername(), sysUser);
        return sysUser;
    }

    public default void remove(String username){
        userMap.remove(username);
    }
}